package com.magicode.cms.service.impl;

import java.net.CookieManager;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.criteria.From;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.jgroups.util.GetNetworkInterfaces;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.validation.ObjectError;
import org.springframework.web.servlet.ModelAndView;

import com.magicode.cms.entiy.base.Dictionary;
import com.magicode.cms.entiy.base.NewsComment;
import com.magicode.cms.entiy.base.Operate;
import com.magicode.cms.entiy.base.Picture;
import com.magicode.cms.entiy.base.Role;
import com.magicode.cms.entiy.base.ThirdPartyUser;
import com.magicode.cms.entiy.base.TvFilmPerson;
import com.magicode.cms.entiy.base.User;
import com.magicode.cms.entiy.base.UserCookie;
import com.magicode.cms.entiy.base.Video;
import com.magicode.cms.entiy.base.VipBuyHistory;
import com.magicode.cms.service.IUserService;
import com.magicode.cms.dao.IUserDao;
import com.magicode.common.dao.ICommonDaoService;
import com.magicode.common.dao.PageResults;
import com.magicode.portal.common.assist.personal.FriendsInfo;

@Service("serviceuser")
public class UserServiceImpl extends BaseServiceImpl<User,IUserDao> implements IUserService {

	// 存放最新登陆的用户信息，key为user_id,value为sessionID
	private Map<String, String> loginMap;
	public  static String loginUserId = "userId";
	public static String sessionId = "jsid";
	@Override
	public User getUserByid(String id) throws Exception {
		String hql=" from "+User.class.getName() +" t  "
				+ "left outer join fetch t.sex "
				+ "left outer join fetch t.userType "
				+ "left outer join fetch t.mainPic where t.id=:id ";
		Map<String,String> map = new HashMap<String, String>();
		map.put("id", id);
		List list = userDao.getCommonDaoService().queryList(hql, map);
		return (null!=list && list.size()>0)? (User)list.get(0):null;
	}

	@Autowired
	@Qualifier("daoUser")
	private IUserDao userDao;

	@Autowired
	@Qualifier("commonDaoService")
	private ICommonDaoService commonDaoService;
	
	@Override
	public IUserDao getDao() throws Exception {
		return userDao;
	}

	public IUserDao getUserDao() {
		return userDao;
	}
	/**
	 * 判断是否第三方登陆时头像改变了
	 * @param user
	 * @param imageUrl
	 * @return
	 */
	@Override
	public boolean isUpdateUserHeadPic(User user,String imageUrl){
		if(null != user){
			String hql = " from " + ThirdPartyUser.class.getName() + " t left outer join fetch t.user where t.user.id='"+user.getId()+"' ";
			List<ThirdPartyUser> thpUsers = this.commonDaoService.getListByHQL(hql);
			if(null != thpUsers && thpUsers.size() > 0){
				ThirdPartyUser thpUser = thpUsers.get(0);
				String originHeadImageUrl = thpUser.getOriginHeadImageUrl();
				if(null != originHeadImageUrl && !imageUrl.equals(originHeadImageUrl)){
					thpUser.setOriginHeadImageUrl(imageUrl);//将最新的url更新上去
					this.commonDaoService.update(thpUser);
					return true;
				}
			}
		}
		return false;
	}
	@Override
	public List<Map<String, Object>> getBeanInfo() {
		List<Map<String, Object>> beaninfo = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(json_key, "loginName");
		map.put(json_title, "昵称");
		map.put("width", 90);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "userName");
		map.put(json_title, "姓名");
		map.put("width", 90);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "userTypeId");
		map.put(json_title, "用户类型");
		map.put("width", 90);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "rolesName");
		map.put(json_title, "角色");
		map.put("width", 90);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "email");
		map.put(json_title, "Email"); 
		map.put("width", 90);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "mobile");
		map.put(json_title, "手机号");
		map.put("width", 90);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "createTime");
		map.put(json_title, "创建时间");
		map.put("width", 130);
		beaninfo.add(map);
		return beaninfo;
	}
	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}
	
	
	
	@Override
	public String getHql(Map<String, String> querywhere) throws Exception {
		String 	hql = " from "+com.magicode.cms.entiy.base.User.class.getName()+" "+entity_alias_name;
		//		+" left join fetch "+entity_alias_name+".userType as ut  ";
		String wherehql = " where 1=1 ";
		if(null==querywhere ||querywhere.isEmpty() ){
			return hql+wherehql;
		}
		if(querywhere.containsKey("roleId")){
			hql = hql+" , "+Role.class.getName()+" tp ";
		}
		if(querywhere.containsKey("mainpic")){
			hql+= " left outer join fetch  "+entity_alias_name+".mainPic";
			querywhere.remove("mainpic");
		}
		if(querywhere.containsKey("fetchSex")){
			hql+= " left join fetch "+entity_alias_name+".sex " ;
		}
		if(querywhere.containsKey("userType")){
			hql+= " left join fetch "+entity_alias_name+"."+querywhere.get("userType");
			querywhere.remove("mainpic");
		}else{
			hql+=" left join "+entity_alias_name+".userType as ut  ";
		}
		if(querywhere.containsKey("userTypeId")){
			wherehql = wherehql+" and "+entity_alias_name+".userType.id = '"+querywhere.get("userTypeId")+"' ";
		}
		if(querywhere.containsKey("id")){
			wherehql +=" and "+entity_alias_name+".id='"+querywhere.get("id")+"'";
		}
		if(querywhere.containsKey("loginName")){
			wherehql +=" and "+entity_alias_name+".loginName='"+querywhere.get("loginName")+"'";
		}
		if(querywhere.containsKey("userName")){
			wherehql +=" and "+entity_alias_name+".userName like '%"+querywhere.get("userName")+"%' ";
		}
		if(querywhere.containsKey("userloginName")){
			wherehql +=" and ("+entity_alias_name+".loginName like '%"+querywhere.get("userloginName")+"%' "
						+ " or "+entity_alias_name+".userName like '%"+querywhere.get("userloginName")+"%' ) ";
		}
		if(querywhere.containsKey("password")){
			wherehql +=" and "+entity_alias_name+".password='"+querywhere.get("password")+"'";
		}
		if(querywhere.containsKey("email")){
			wherehql +=" and "+entity_alias_name+".email='"+querywhere.get("email")+"'";
		}
		if(querywhere.containsKey("mobile")){
			wherehql +=" and "+entity_alias_name+".mobile like '%"+querywhere.get("mobile")+"%' ";
		}
		if(querywhere.containsKey("valid")){
			wherehql +=" and "+entity_alias_name+".valid='"+querywhere.get("valid")+"'";
		}
		if(querywhere.containsKey("roleId")){
			wherehql = wherehql+" and tp.id = '"+querywhere.get("roleId")+"'";
			wherehql = wherehql+ " and  tp in elements("+entity_alias_name+".roles) ";
		}
			
		
		// 第三方登录 QQ登录处理 
		if(querywhere.containsKey("thirdPartyId")){
			hql="select "+entity_alias_name+hql;
			hql+=", "+ ThirdPartyUser.class.getName()+" t1  ";
			wherehql +=" and t1.user.id="+entity_alias_name+".id and t1.thirdPartyId='"+querywhere.get("thirdPartyId")+"'";
		}
//		多种登录方式
		if(querywhere.containsKey("multiLoginName") && querywhere.containsKey("multiPassword")){
			
			wherehql +=" and "
					+ " ( "
						+ " ( "
						+ " "+entity_alias_name+".loginName ='"+querywhere.get("multiLoginName")+"' or "
						+ " "+entity_alias_name+".email ='"+querywhere.get("multiLoginName")+"' or "
						+ " "+entity_alias_name+".mobile ='"+querywhere.get("multiLoginName")+"' "
						+ " ) "
						+ " and "+entity_alias_name+".password ='"+querywhere.get("multiPassword")+"'"
					+ " ) ";
		}
		return hql+wherehql;
	}
	@Override
	public List<Map<String, Object>> grid(Map<String, String> querywhere) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		try {
			Integer start = this.getGridStartOrSize(querywhere, 0, field_grid_start);
			Integer size = this.getGridStartOrSize(querywhere, 0, field_grid_size);
//			querywhere.put("roles", "roles");
			String hql = this.getHql(querywhere);
			Map<String,String> gridsel = new HashMap<String,String>();
			gridsel.put(field_id, ""+entity_alias_name+".id as id ");
			gridsel.put("loginName", ""+entity_alias_name+".loginName as loginName ");
			gridsel.put("userName", ""+entity_alias_name+".userName as userName ");
			gridsel.put("userTypeId", "ut.title as userTypeId ");
			gridsel.put("email", ""+entity_alias_name+".email as email ");
			gridsel.put("mobile", ""+entity_alias_name+".mobile as mobile");
			gridsel.put("createTime", ""+entity_alias_name+".createTime as createTime");
			 list = this.queryMapDataList(hql, gridsel,start , size);
			String hql1 = "select distinct new map(t.id as id , d.name as title ) from "+Role.class.getName()+" d , "+User.class.getName()+" t "
					+ " where  d in elements(t.roles) " ;
			String propertyName = "rolesName";
			String connectStr = ",";
			list =  commonDaoService.getRelateProByList(hql1, ",", propertyName, list);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return list;
	}

	
	@Override
	public List<Map<String, Object>> simpleSelect(Map<String, String> querywhere) {
		try {
			String hql = this.getHql(querywhere);
			Map<String,String> gridsel = new HashMap<String,String>();
			gridsel.put(field_id, ""+entity_alias_name+".id as id ");
			gridsel.put(field_title, ""+entity_alias_name+".userName as text ");
			return this.queryMapDataList(hql, gridsel,0 , 0);
		} catch (Exception e) {
			return new ArrayList<Map<String, Object>>();
		}
	}
	
	@Override
	public User Login(String name, String pwd) throws Exception{
		try {
			Map<String,String> map = new HashMap<String,String> ();
			map.put("multiLoginName", name);
			map.put("multiPassword", pwd);
			map.put("valid", "1");
			map.put("userType", "userType");
			map.put("fetchSex", "1");
			
			//是否获取头像参数
			map.put("mainpic", "yes");
			String hql = this.getHql(map);
			List<User> user = this.getDao().queryDataList(hql, 0, 0);
			return  user.size()>0?user.get(0) : null;
		} catch (Exception e) {
			throw new Exception("getUserByEmail error by name=["+name+"] pwd=["+pwd+"]"+e.getMessage());
		}
		
		
	}

	@Override
	public User getUserByLoginName(String name) throws Exception {
		try {
			String hql = " from "+User.class.getName()+" t  left outer join fetch t.mainPic "
					+ "where  t.loginName='"+name+"' " ;
			List<User> user = this.getDao().queryDataList(hql, 0, 0);
			return  user.size()>0?user.get(0) : null;
		} catch (Exception e) {
			throw new Exception("getUserByEmail error by LoginName=["+name+"]"+e.getMessage());
			
		}
	}
	
	@Override
	public User getUserByLoginNameId(String name,String Id) throws Exception {
		String hql = " from "+User.class.getName()+" t  left outer join fetch t.mainPic "
				+ "where t.id !='"+Id+"'  and t.loginName='"+name+"' " ;
		List<User> user = this.getDao().queryDataList(hql, 0, 0);
		return  user.size()>0?user.get(0) : null;
	}
	
	@Override
	public User getUserByMobile(String name) throws Exception {
		try {
			String hql = " from "+User.class.getName()+" t  left outer join fetch t.mainPic "
					+ "where  t.mobile='"+name+"' " ;
			List<User> user = this.getDao().queryDataList(hql, 0, 0);
			return  user.size()>0?user.get(0) : null;
		} catch (Exception e) {
			throw new Exception("getUserByEmail error by mobile=["+name+"]"+e.getMessage());
			
		}
	}
	
	@Override
	public User getUserByLoginMobileId(String name,String Id) throws Exception {
		String hql = " from "+User.class.getName()+" t  left outer join fetch t.mainPic "
				+ "where t.id !='"+Id+"' and t.mobile='"+name+"' " ;
		List<User> user = this.getDao().queryDataList(hql, 0, 0);
		return  user.size()>0?user.get(0) : null;
	}
	

	@Override
	public User getUserByEmail(String name) throws Exception{
		try {
			String hql = " from "+User.class.getName()+" t  left outer join fetch t.mainPic "
					+ "where  t.email='"+name+"'" ;
			List<User> user = this.getDao().queryDataList(hql, 0, 0);
			return  user.size()>0?user.get(0) : null;
		} catch (Exception e) {
			throw new Exception("getUserByEmail error by email=["+name+"]"+e.getMessage());
		}
	}
	@Override
	public User getUserByEmailId(String name,String Id) throws Exception {
		String hql = " from "+User.class.getName()+" t  left outer join fetch t.mainPic "
				+ "where t.id !='"+Id+"' and t.email='"+name+"'" ;
		List<User> user = this.getDao().queryDataList(hql, 0, 0);
		return  user.size()>0?user.get(0) : null;
	}
	/**
	 * 活动用户密码
	 * @throws Exception 
	 */
	@Override
	public String getPassword(String id) throws Exception {
		// TODO Auto-generated method stub
		String result = null;
		String hql = "select t.password from "+User.class.getName()+" t  where t.id = '"+id+"' ";
		List<String> passList = this.getDao().getCommonDaoService().getListByHQL(hql);
		if(passList != null && passList.size() > 0){
			result = passList.get(0);
		}
		return result;
	}

	@Override
	public VipBuyHistory getUserByLoginId(String Id) throws Exception {
		String hql = " from "+VipBuyHistory.class.getName()+" t left join fetch t.status "
				+ "where t.status.code = 'Success' and t.vipuser.id =? and t.validEndTime >? order by t.validEndTime desc ";
		//System.out.println(new Date());
		List<VipBuyHistory> list = this.commonDaoService.getListByHQL(hql,Id,new Date());
		VipBuyHistory user = null;
		if(list != null && list.size() > 0){
			user = (VipBuyHistory)list.get(0);
		}
		return user;
	}
	
	@Override
	public List<FriendsInfo> getUserFriends(String userid) throws Exception {
		List<User> users = this.getDao().queryDataList(this.getHql(null)+" and t.loginName is not null ", 0, 2);
		List<FriendsInfo> infos = new ArrayList<FriendsInfo>();
		for(User user : users){
			FriendsInfo info = new  FriendsInfo();
			String username = "";
			if(null!=user.getUserName()&&!"".equals(user.getUserName()))
			{
				username = user.getUserName();
			}
			else{
				username =user.getLoginName();
			}
			info.setName(username);
			info.setId(user.getId());
			info.setMark("好友");
			info.setFriendcount("10");
			infos.add(info);
		}
		return infos;
	}
@Override
	public User getUserByThirdPartyId(String thirdPartyId) throws Exception {
		try {
			Map<String,String> map = new HashMap<String,String> ();
			map.put("thirdPartyId", thirdPartyId);
			map.put("mainpic", "t");
			List<User> user = this.getDao().queryDataList(this.getHql(map), 0, 0);
			return  user.size()==1?user.get(0) : null;
		} catch (Exception e) {
			throw new Exception("getUserByQQLoginName error by qq=["+thirdPartyId+"]"+e.getMessage());
		}
	}
	/**
	 * 向cookie里设置用户
	 * @param user
	 */
	public void addLoginCookie(User user,HttpServletRequest request,HttpServletResponse response){
		Cookie ckUsername, ckSessionid;
		   // 如果用户选择了“两周内自动登录”，则向用户发送两个cookie。
		   // 一个cookie记录用户名，另一个记录唯一的验证码，
		   // 并将此验证码写入数据库，以备用户返回时查询。(防止伪造cookie)
		   ckUsername = new Cookie(loginUserId, user.getId()); // user是代表用户的bean
		   ckUsername.setMaxAge(60 * 60 * 24 * 14);   //设置Cookie有效期为14天
		   response.addCookie(ckUsername);
		   HttpSession session = request.getSession();
		   String sessionid = session.getId(); // 取得当前的session id
		   ckSessionid = new Cookie(sessionId, sessionid);
		   ckSessionid.setMaxAge(60 * 60 * 24 * 14);
		   ckSessionid.setPath("/");
		   response.addCookie(ckSessionid);
		   // 在数据库中插入相应记录
		   Calendar cal = Calendar.getInstance();
		   cal.add(Calendar.DATE, 14);
//		   	加14天
		   addUserCookie(user, sessionid,cal.getTime());
		}
	/**
	 * 向cookie里设置用户
	 * @param user
	 */
	public void deleteLoginCookie(User user,HttpServletRequest request,HttpServletResponse response){
		
		   // 如果用户选择了“两周内自动登录”，则向用户发送两个cookie。
		   // 一个cookie记录用户名，另一个记录唯一的验证码，
		   // 并将此验证码写入数据库，以备用户返回时查询。(防止伪造cookie)
		 Cookie[] cookies = null;
		  cookies = request.getCookies();
		  System.out.println();
		  if(cookies != null){
			  for(Cookie ck : cookies){
				  ck.setMaxAge(0);
				   response.addCookie(ck);
			  }
		  }
//		   	
		   deleteUserCookie(user);
		}
	/**
	 * 创建UserCookie
	 * 首先删除所有该用户相关UserCookie，再插入UserCookie
	 * @param user
	 * @param sessionid
	 * @param expireTime
	 */
	private void addUserCookie(User user, String sessionid, Date expireTime) {
		// TODO Auto-generated method stub
		String ucSql = "select t from "+UserCookie.class.getName()+" t where t.user.id =  '"+user.getId()+"' ";
		
		List list = this.userDao.getCommonDaoService().getListByHQL(ucSql);
		
		for(Object obj : list){
			if(obj instanceof UserCookie){
				UserCookie uc = (UserCookie) obj;
				this.userDao.getCommonDaoService().delete(uc);
			}
		}
		UserCookie uc = new UserCookie();
		uc.setCreateTime(new Date());
		uc.setExpireTime(expireTime);
		uc.setUser(user);
		uc.setSessionId(sessionid);
		this.userDao.getCommonDaoService().save(uc);
	}
	/**
	 * 删除UserCookie
	 * 删除所有该用户相关UserCookie
	 * @param user
	 * @param sessionid
	 * @param expireTime
	 */
	public void deleteUserCookie(User user) {
		// TODO Auto-generated method stub
		if(user == null){
			return ;
		}
		String ucSql = "select t from "+UserCookie.class.getName()+" t where t.user.id =  '"+user.getId()+"' ";
		
		List list = this.userDao.getCommonDaoService().getListByHQL(ucSql);
		
		for(Object obj : list){
			if(obj instanceof UserCookie){
				UserCookie uc = (UserCookie) obj;
				this.userDao.getCommonDaoService().delete(uc);
			}
		}
	}
	/**
	 * cookie里读取，如果该用户的sessionId在UserCookie并且未超期时，将User写入session中；
	 * 
	 * @param user
	 */
	public boolean getLoginCookie(HttpServletRequest request){
		boolean result = false;
		  Cookie[] cookies = null;
		  cookies = request.getCookies();
		  System.out.println();
		  if(cookies != null){
			  for(Cookie ck : cookies){
				  System.out.println("cookie getName = "+ck.getName());
				  System.out.println("cookie getValue = "+ck.getValue());
	//			  如果是登录sessionId
				  if(sessionId.equals(ck.getName())){
					  UserCookie uc = getserCookieInSystem(ck.getValue());
					  if(uc != null){
						  result = true;
						  try {
							request.getSession().setAttribute("user", getUserByid(uc.getUser().getId()));
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					  }
				  }
			  }
		  }
		
		return result;
	}
	/**
	 * 登录后设置用户Session
	 * 包括：
	 * 1.Session设置User
	 * 2。Session设置VipBuyHistory
	 * 3.Cookie设置User
	 * @param user
	 * @param request
	 * @throws Exception
	 */
	@Override
	public void setUserSession(User user , HttpServletRequest request) throws Exception{
		if(user != null && user.getId() != null){
			try{
			System.out.println("User is not Null");
			request.getSession().setAttribute("user", user);
			VipBuyHistory vipBuyHistory = getUserByLoginId(user.getId());
			System.out.println("vipBuyHistory is not Null");
			if(vipBuyHistory  != null){
				request.getSession().setAttribute("vipBuyHistory", vipBuyHistory);
				System.out.println("vipBuyHistory set session");
			}
			if (null == loginMap) {
				loginMap = new HashMap<String, String>();
			}
			loginMap.put(user.getId(), request.getSession().getId());
			}
			catch(Exception e){
				e.printStackTrace();
			}
		}
	}
	/**
	 * 退出后清除用户Session
	 * 包括：
	 * 1.Session清除User
	 * 2。Session清除VipBuyHistory
	 * 3.LoginMap清除SeesionId
	 */
	@Override
	public void userExit( HttpServletRequest request) throws Exception{
		Object obj = request.getSession().getAttribute("user");
		if (null != obj) {
			request.getSession().removeAttribute("user");
			String userId = null;
			if(obj != null){
				userId = ((User) obj).getId();
			}
			if(this.loginMap != null && this.loginMap.containsKey(userId)){
				this.loginMap.remove(userId);
			}
//			this.getUserService().getLoginMap().remove(user_.getId());
//			request.getSession().invalidate();
		}
		request.getSession().invalidate();
	}
	/**
	 * 根据cookie中的sessionId得到UserCookie
	 * 其中要fetch出User机器MainPic
	 * @param sessionId
	 * @return
	 */
	private UserCookie getserCookieInSystem(String sessionId){
		UserCookie uc = null;
		Calendar cal = Calendar.getInstance();
		SimpleDateFormat  sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); 
//		查到超期日期范围内的用户UserCookie
		String sql = "select t from "+UserCookie.class.getName()+" t "
				+ " left outer join fetch t.user "
//				+ " left outer join fetch t.user.mainPic "
				+ "  where t.sessionId = '"+sessionId+"' and "+ sql_date_method + "("
					+ "t.expireTime ,'"+ sql_time_format + "') > '"+sdf.format(new Date())+"'  "  ;  
		List list = null;
		try{
			list = this.userDao.getCommonDaoService().getListByHQL(sql);
		}catch(Exception e){
			e.printStackTrace();
		}
		if(list != null && list.size() > 0){
			uc = (UserCookie)list.get(0);
		}
		return uc;
	}

	@Override
	public User multiLogin(String name, String pwd)
			throws Exception {
		try {
			Map<String,String> map = new HashMap<String,String> ();
			map.put("multiLoginName", name);
			map.put("multiPassword", pwd);
			map.put("valid", "1");
			//是否获取头像参数
			map.put("mainpic", "yes");
			String hql = this.getHql(map);
			List<User> user = this.getDao().queryDataList(hql, 0, 0);
			return  user.size()>0?user.get(0) : null;
		} catch (Exception e) {
			throw new Exception("multiLogin error by name=["+name+"] pwd=["+pwd+"]"+e.getMessage());
		}
	}

	@Override
	public Picture getMainPicId(String userId) throws Exception {
		// TODO Auto-generated method stub
		String hql = "select t.mainPic from "+User.class.getName()+" t where t.id = '"+userId+"' ";
		Picture pic = null;
		List<Object> picList = this.queryDataList(hql);
		if(picList != null && picList.size() > 0){
			pic = (Picture) picList.get(0);
		}
		return pic;
	}

	@Override
	public void createUser(ThirdPartyUser thirduser, User user) {
		try {
			user.setCreateTime(new Date());
			userDao.createObject(user);
			if(null!=thirduser){
				thirduser.setUser(user);
				userDao.createObject(thirduser);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

	@Override
	public Map<String, String> getLoginMap() {
		return loginMap;
	}

//	@Override
	public void setLoginMap(Map<String, String> loginMap) {
		this.loginMap = loginMap;
	}

	@Override
	public User getCookieSessionUser(HttpServletRequest request) {
		// TODO Auto-generated method stub
		return null;
	}
	
	
}
